<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
	*{
		padding: 0px;
		margin: 0px;
	}
	#lanqiu{
		position: absolute;
		top: 0px;
		left: 400px;
	}
	#floor{
		width: 100%;
		height:400px;
		border-bottom: 3px solid blue; 
	}
</style>
<script type="text/javascript">
window.onload = function(){
	var lanqiu = document.getElementById('lanqiu');//获得篮球对象
	document.getElementById('btn').onclick = function(){
		var speed = 1;//设立速度变量
		var timer = setInterval(function(){//设立定时器，让小球下落
			speed += 3;
			var old_top = lanqiu.offsetTop;//获得旧的top值
			var new_top = old_top+speed;//计算新的top值
			if(new_top>=300){
				new_top = 300;
				speed *= -0.9;//速度损失并且改变方向
			}
			if(-1<speed && speed<1){
				speed ==0;
			}
			if(speed==0 && new_top==300){//判断结束条件请清掉定时器
				clearInterval(timer);
			}
			lanqiu.style.top = new_top+'px';

		},10)
	}
}
</script>
</head>

<body>
	<img src="lanqiu.jpg" alt="" id="lanqiu" />
	<div id="floor">
		<input type="button" value="走你！" id="btn" />
	</div>
</body>
</html>
